package com.ycf.untils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author ycf
 */
public class MybatisUnities {
    private static SqlSessionFactory sqlSessionFactory;
    static {
        String res = "Mybatis-config.xml";
        try {
            InputStream resourceAsStream = Resources.getResourceAsStream(res);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static SqlSession getSqlSession() {

        return sqlSessionFactory.openSession(true);
    }
}
